package capricornus.components.flower
{
	import capricornus.core.RefreshManager;
	import capricornus.core.StageManager;
	import capricornus.events.RefreshEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.utils.getTimer;

	internal class FlowerRefreshController extends EventDispatcher
	{
		private static var _ins:FlowerRefreshController = null;
		
		private var _isStart:Boolean = false;
		
		public function FlowerRefreshController()
		{
		}
		
		public static function get instance():FlowerRefreshController
		{
			if( null==_ins )
			{
				_ins = new FlowerRefreshController();
			}
			
			return _ins;
		}
		
		public function start():void
		{
			if( !_isStart )
			{
				_isStart = true;
				RefreshManager.instance.addEventListener( RefreshEvent.REFRESH, onRefresh );
			}
		}
		
		public function stop():void
		{
			if( _isStart )
			{
				_isStart = false;
				RefreshManager.instance.removeEventListener( RefreshEvent.REFRESH, onRefresh );
			}
		}
		
		private function onRefresh( e:RefreshEvent ):void
		{
			dispatchEvent( new FlowerRefreshEvent( FlowerRefreshEvent.REFRESH, e.data ) );
		}
	}
}